#!/bin/bash
baseDirForScriptSelf=$(cd "$(dirname "$0")"; pwd)
source ${baseDirForScriptSelf}/source.sh
# 安装gn
source ${baseDirForScriptSelf}/proxy.sh
DownLoad_URL=https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz
file_name=`basename ${DownLoad_URL}`
cd ${work_dir}
if [ ! -f "${work_dir}/${file_name}" ];then
    wget –-no-check-certificate "${DownLoad_URL}" >>${baseDirForScriptSelf}/init_run.log 2>&1
    check_line=$((LINENO-1))
    if [ $? -gt 0 ];then
       push_error "${check_line}" "gcc_riscv32 download failed,please check!" "1"
    else
       check_sha256 "${DownLoad_URL}" "${work_dir}/${file_name}"
    fi
fi
if [ -d ~/gcc_riscv32 ];then
    mv ~/gcc_riscv32 ~/gcc_riscv32_bak_${unix_time}
fi
mkdir ~/gcc_riscv32
tar -zxf ${work_dir}/gcc_riscv32-linux-7.3.0.tar.gz -C ~/gcc_riscv32 >>${baseDirForScriptSelf}/init_run.log 2>&1
BIN_FILE=`find ~/gcc_riscv32 -maxdepth 5 -type f -name 'riscv32-unknown-elf-gcc'`
BIN_PATH=`dirname ${BIN_FILE}`
sudo bash -c "echo 'export PATH=${BIN_PATH}:\$PATH' >/etc/profile.d/gcc_riscv32.sh"
source /etc/profile
source /etc/profile.d/gcc_riscv32.sh
gcc_riscv32_version=`riscv32-unknown-elf-gcc --version|grep riscv32`
if [ $? -gt 0 ];then
    echo  -e "${failed_color},gcc_riscv32 install failed.Please check!"
    exit 1
else
    echo  -e "${success_color},gcc_riscv32 install success.Revision:${gcc_riscv32_version}"
fi